var timer;
var usersTimer;
function init(){
    $('#authForm').submit(function () {
        authorizeUser();
        return false;
    });
    $('#send').click(send);
    $('#text').keydown(function (e) {
        var sendByEnter = $('#sendByEnter').attr('checked');
        if (e.ctrlKey && e.keyCode == 13) {
            if (sendByEnter) {
                $(this).val($(this).val() + '\n');
            } else {
                send();
            }
        }
        if (!e.ctrlKey && e.keyCode == 13) {
            if (sendByEnter) {
                send();
            }
        }
    });
    for (smile in smiles) {
        var smileImg = $('<div><img src="/public/img/smile/' + smiles[smile] + '"></div>');
        smileImg.find('img').attr('title', smile);
        $('#smiles').append(smileImg);
    }
    $('#smileButton').click(function () {
        $('#smiles').show(300);
    });
    $('#smiles img').click(function () {
        var text = $('#text');
        text.val(text.val() + $(this).attr('title'));
        $(this).parent().parent().hide();
    });
    $("html").mouseup(function () {
        $("#smiles:visible").hide();
    });
    $('#quote .close').click(function () {
        $(this).parent().hide(500);
    });
}
String.prototype.replaceAll = function (search, replace) {
    return this.split(search).join(replace);
}
function RecurringTimer(callback, delay) {
    var timerId, start, remaining = delay;

    this.pause = function () {
        window.clearTimeout(timerId);
        remaining -= new Date() - start;
    };

    var resume = function () {
        start = new Date();
        timerId = window.setTimeout(function () {
            remaining = delay;
            resume();
            callback();
        }, remaining);
    };

    this.resume = resume;
    this.resume();
}
